const router = require('koa-router')()

router.prefix('/user')

router.get('/info', async (ctx, next) => {
    console.log(ctx.state.user);
    console.log(ctx.parmas);
    let data;
    if(ctx.state.user.user_auth === 'admin_per') {
        let sql = "select * from admin where user_id = ?";
        let res = await ctx.db.EXCUTE(sql, ctx.state.user.user_id)
        data = res[0];
    } else if(ctx.state.user.user_auth === 'teacher_per') {
        let sql = "select teacher.user_id, teacher.avatar, teacher.teacher_name, teacher.user_name, teacher.signature, teacher.institute_id,  institute.institute_name from teacher join institute on teacher.institute_id = institute.institute_id where teacher.user_id = ?";
        let res = await ctx.db.EXCUTE(sql, [ctx.state.user.user_id]);
        data = res[0];
    }
    console.log(data,"data");
    ctx.body = {code: "200", msg: "成功获取信息", data}
})

router.post('/logout', async (ctx, next) => {
    console.log(ctx.request.body);
    ctx.body = {code: 200, msg: '退出成功'}; 
})

module.exports = router